namespace KinonekoSoftware.Studio.Pages.Theories
{
    partial class WorldViewConfigTheoryViewModel
    {

        //-------------------------------------------------
        //
        //          Command Handlers
        //
        //-------------------------------------------------

        private async void DoNewVocabularyCommand()
        {
            var r = await NewVocabularyViewModel.Create();

            if (!r.IsFinished)
            {
                return;
            }

            var val = r.Value;

            //
            //
            _theory_vocabulary.Add(val);

            //
            //
            Vocabularies.Add(val);

            //
            Save();
        }

        private async void DoResetVocabularyCommand()
        {

            if (!await DangerOperation(TitleSR.DangerOperation, TextSR.Remove_Item_All))
            {
                return;
            }
            
            
            
            Vocabularies.Clear();
            _theory_vocabulary.Clear();
            //
            Save();
        }

        private async void DoEditVocabularyCommand(Vocabulary element)
        {
            if (element is null)
            {
                return;
            }

            var r = await NewVocabularyViewModel.Edit(element);

            if (!r.IsFinished)
            {
                return;
            }

            //
            //
            Save();
            _theory_vocabulary.Update(element);
        }

        private async void DoRemoveVocabularyCommand(Vocabulary element)
        {
            if (element is null)
            {
                return;
            }

            if (!await RemoveItem())
            {
                return;
            }

            Vocabularies.Remove(element);
            _theory_vocabulary.Remove(element);

            //
            //
            Save();
        }


        public ICommandEX NewVocabularyCommand    { get; }
        public ICommandEX EditVocabularyCommand   { get; }
        public ICommandEX ResetVocabularyCommand  { get; }
        public ICommandEX RemoveVocabularyCommand { get; }

        public ObservableCollection<Vocabulary> Vocabularies { get; }
    }
}